🎖️GitЯра🎖️
Node / meshtastic / Meshtastic-Android / files / core / prefs / src / commonMain / kotlin / org / meshtastic / core / prefs / FlowCache.kt
Displaying Raw • Download
core/prefs/src/commonMain/kotlin/org/meshtastic/core/prefs/FlowCache.kt renovate/net.java.dev.jna-jna-5.x (5a8f4966) Text, 1.89 KB
T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.prefs
Tff7b72import T7ee787kotlinx.atomicfu.AtomicRef
Tff7b72import T7ee787kotlinx.collections.immutable.PersistentMap
T8b949e/**
* Look up [key] in [cache]; if absent, construct a value via [build] and insert it atomically.
*
* [build] is wrapped in a [Lazy] before being published to [cache], so concurrent first-access of the same key never
* invokes [build] more than once — only the winner of the CAS has its [Lazy] evaluated, and all readers share that same
* result. This matters when [build] eagerly launches a coroutine (e.g. `Flow.stateIn(scope, Eagerly, …)`): the naive
* approach would leak the losing coroutine into a never-cancelled scope.
*/
Tf0883e@SuppressTb4b4b4(Ta5d6ff"Ta5d6ffReturnCountTa5d6ff"Tb4b4b4)
Tff7b72internal Tff7b72inline Tff7b72fun Tff7b72<Te6edf3KTb4b4b4, Te6edf3VTff7b72> Td2a8ffcachedFlowTb4b4b4(
Te6edf3cacheTb4b4b4: Te6edf3AtomicRefTff7b72<Te6edf3PersistentMapTff7b72<Te6edf3KTb4b4b4, Te6edf3LazyTff7b72<Te6edf3VTff7b72>Tff7b72>Tff7b72>Tb4b4b4,
Te6edf3keyTb4b4b4: Te6edf3KTb4b4b4,
Te6edf3crossinline Te6edf3buildTb4b4b4: Tb4b4b4(Tb4b4b4) Tff7b72-Tff7b72> Te6edf3VTb4b4b4,
Tb4b4b4)Tb4b4b4: Te6edf3V Tb4b4b4{
Te6edf3cacheTb4b4b4.Te6edf3valueTff7b72[Te6edf3keyTff7b72]Tff7b72?.Te6edf3let Tb4b4b4{
Tff7b72return Tffa657itTb4b4b4.Te6edf3value
Tb4b4b4}
Tff7b72val Te6edf3newLazy Tff7b72= Te6edf3lazyTb4b4b4(Te6edf3LazyThreadSafetyModeTb4b4b4.Te6edf3SYNCHRONIZEDTb4b4b4) Tb4b4b4{ Te6edf3buildTb4b4b4(Tb4b4b4) Tb4b4b4}
Tff7b72while Tb4b4b4(Tff7b72trueTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3current Tff7b72= Te6edf3cacheTb4b4b4.Te6edf3value
Te6edf3currentTff7b72[Te6edf3keyTff7b72]Tff7b72?.Te6edf3let Tb4b4b4{
Tff7b72return Tffa657itTb4b4b4.Te6edf3value
Tb4b4b4}
Tff7b72if Tb4b4b4(Te6edf3cacheTb4b4b4.Te6edf3compareAndSetTb4b4b4(Te6edf3currentTb4b4b4, Te6edf3currentTb4b4b4.Te6edf3putTb4b4b4(Te6edf3keyTb4b4b4, Te6edf3newLazyTb4b4b4)Tb4b4b4)Tb4b4b4) Tb4b4b4{
Tff7b72return Te6edf3newLazyTb4b4b4.Te6edf3value
Tb4b4b4}
Tb4b4b4}
Tb4b4b4}
Served by rngit 1.5.0 - Generated in 0.05s